//
//  SDSettingViewController.m
//  SuperDoctor
//
//  Created by 李忠 on 7/5/16.
//  Copyright © 2016 SD. All rights reserved.
//

#import "SDSettingViewController.h"
#import "SDGRCell.h"
#import "SDRetroactionController.h"
#import "SDLeftViewController.h"
#import "NSUserDefaults+SDExtension.h"

@interface SDSettingViewController ()<UITableViewDataSource,UITableViewDelegate>
//cell的标题数组
@property(nonatomic,strong)NSArray *titleArr;

@property(nonatomic,strong)UITableView *tvb_retroaction;

@end

@implementation SDSettingViewController


#pragma mark
#pragma mark - 数组懒加载赋值
- (NSArray *)titleArr{

    if (_titleArr == nil) {
        
        _titleArr = [NSArray array];
        _titleArr = @[@"用户反馈",@"加符号说明",@"修改密码",@"注销用户"];
        
    }
    
    return _titleArr;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    UITableView *tvb_retroaction = [[UITableView alloc] init];
    tvb_retroaction.frame = self.view.frame;
    tvb_retroaction.delegate = self;
    tvb_retroaction.dataSource = self;
    tvb_retroaction.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:tvb_retroaction];
    self.tvb_retroaction = tvb_retroaction;
    

    
    }


#pragma mark
#pragma mark - 数据源代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.titleArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SDGRCell *cell = [[SDGRCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    
    cell.lb_retroaction.text = self.titleArr[indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        SDRetroactionController *VC_retroaction = [[SDRetroactionController alloc] init];
        
//        
//        [self presentViewController:VC_retroaction animated:NO completion:nil];
//
        [self.navigationController pushViewController:VC_retroaction animated:YES];
    }else if(indexPath.row == 3){
        [self noticeLoginOut];
    }
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

- (void)noticeLoginOut{
    UIAlertController *loginOutAlert = [UIAlertController alertControllerWithTitle:@"" message:@"是否登出" preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *loginOutAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        KLoginout;
    }];
    UIAlertAction *noLoginOutAtion = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [loginOutAlert addAction:loginOutAction];
    [loginOutAlert addAction:noLoginOutAtion];
    
    [self presentViewController:loginOutAlert animated:YES completion:nil];
}

@end
